package com.yuqingxin.redisCacheApi.controller;

import com.yuqingxin.redisCacheApi.common.redisCache.RedisCache;
import com.yuqingxin.redisCacheApi.common.result.Result;
import com.yuqingxin.redisCacheApi.common.result.ResultEnum;
import com.yuqingxin.redisCacheApi.dto.TestDto;
import com.yuqingxin.redisCacheApi.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("test1")
    @RedisCache(cron = "* */7 * * * *",timeout = 6, timeUnit = TimeUnit.MINUTES)
    public Result<Map<String,Object>> test1(String a1, Integer a2, BigDecimal a3){
        return Result.result(ResultEnum.SUCCESS, testService.test1(a1, a2, a3));
    }


    @GetMapping("test2")
    @RedisCache()
    public Result<Map<String,Object>> test2(TestDto dto){
        return Result.result(ResultEnum.SUCCESS, testService.test2(dto));
    }

    @PostMapping("postTest")
    @RedisCache(cron = "*/7 * * * * *")
    public Result<Map<String,Object>> postTest(@RequestBody TestDto dto){
        return Result.result(ResultEnum.SUCCESS,testService.test2(dto));
    }
}
